package com.example.qxfw.qxybzz.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.qxybzz.service.ImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequiredArgsConstructor
@RequestMapping("/image")
public class ImageController {

    private final ImageService imageService;

    /**
     * 上传图片
     */
    @PostMapping("/saveImage")
    public SysResult saveImage(@RequestParam("data") MultipartFile data, @RequestParam("name") String name) {
        imageService.saveImage(data,name);
        return SysResult.success();
    }

    /**
     * 根据图片id和描述，生成图片
     * @param text
     * @param imageId
     * @return
     */
    @GetMapping("/getImage")
    public SysResult getImage(@RequestParam("text") String text, @RequestParam("imageId") String imageId) {
        imageService.getImage(text, imageId);
        return SysResult.success();
    }

    /**
     * 根据图片id查看图片
     */
    @GetMapping("/getImageById")
    public SysResult getImageById(String imageId) {
        return SysResult.success(imageService.getImageById(imageId));
    }




    /**
     * 根据图片编码和文字描述生成新的图片，并返回图片的且存到mongo中
     * @param text
     * @param imageId
     * @return
     */
    @GetMapping("/getImage2")
    public ResponseEntity<byte[]> getImage2(@RequestParam("text") String text, @RequestParam("imageId") String imageId) {
        return imageService.getImage2(text, imageId);
    }

}
